<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="${basePackageName}.mapper.${ClassName}Mapper">
	<resultMap id="BaseResultMap" type="${ClassName}${setting.entPostfix}">
#foreach(${fieldModel} in ${fieldModelList})
#if($fieldModel.pk)
		<id column="${fieldModel.columnName}" property="${fieldModel.name}" jdbcType="${fieldModel.jdbcType}"/>
#else
		<result column="${fieldModel.columnName}" property="${fieldModel.name}" jdbcType="${fieldModel.jdbcType}"/>
#end
#end
	</resultMap>
	<sql id="Base_Column_List">
#foreach(${fieldModel} in ${fieldModelList})
		${fieldModel.columnName}#if($foreach.hasNext),#end
#end
	</sql>
	<select id="select${ClassName}List" resultMap="BaseResultMap" parameterType="${ClassName}${setting.entPostfix}">
		select
    	<include refid="Base_Column_List"/>
    	from ${schema}.${tableName}
		<where>
	#foreach(${fieldModel} in ${fieldModelList})
	#set($columnName=$fieldModel.columnName)
	#set($javaField=$fieldModel.name)
	#set($javaType=$fieldModel.type)
	#set($jdbcType=$fieldModel.jdbcType)
		<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName = #{$javaField, jdbcType=$jdbcType}</if>
	#end
	</where>
	</select>
	<select id="selectByPrimaryKey" resultMap="BaseResultMap">
    	select
    		<include refid="Base_Column_List"/>
    	from ${schema}.${tableName}
    	where
#foreach(${primaryKey} in ${primaryKeyList})
    		${primaryKey.columnName} = #{${primaryKey.name}, jdbcType=${primaryKey.jdbcType}}
    #if($foreach.hasNext) and #end
#end
</select>
	<delete id="deleteByPrimaryKey" >
		delete from ${schema}.${tableName}
		where
#foreach(${primaryKey} in ${primaryKeyList})
			${primaryKey.columnName} = #{${primaryKey.name}, jdbcType=${primaryKey.jdbcType}}
	#if($foreach.hasNext) and #end
#end
</delete>
	<insert id="insertSelective" parameterType="${ClassName}${setting.entPostfix}">
		insert into ${schema}.${tableName}
		<trim prefix="(" suffix=")" suffixOverrides=",">
#foreach(${fieldModel} in ${fieldModelList})
		<if test="${fieldModel.name} != null">${fieldModel.columnName}#if($foreach.hasNext),#end </if>
#end
		</trim>
		<trim prefix="values (" suffix=")" suffixOverrides=",">
#foreach(${fieldModel} in ${fieldModelList})
		<if test="${fieldModel.name} != null">#{${fieldModel.name},jdbcType=${fieldModel.jdbcType}}#if($foreach.hasNext),#end</if>
#end
		</trim>
	</insert>
	<update id="updateByPrimaryKeySelective" parameterType="${ClassName}${setting.entPostfix}">
		update ${schema}.${tableName}
		<set>
#foreach(${fieldModel} in ${fieldModelList})
			<if test="${fieldModel.name} != null">${fieldModel.columnName} = #{${fieldModel.name},jdbcType=${fieldModel.jdbcType}}#if($foreach.hasNext),#end</if>
#end
		</set>
		where
#foreach(${primaryKey} in ${primaryKeyList})
			${primaryKey.columnName} = #{${primaryKey.name}, jdbcType=${primaryKey.jdbcType}}
	#if($foreach.hasNext) and #end
#end
</update>
</mapper>
